
using System;
using System.IO;
using System.Windows.Forms;

namespace Derm.UnitTest
{
	public class Program
	{
		/// <summary>
		/// Application entry point.
		/// </summary>
		static void Main()
		{
			if (MessageBox.Show("Do you want to execute test RenderContext?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
				// RenderContext
				using (FileStream fs = new FileStream(TestLogName("RenderContext"), FileMode.Create, FileAccess.Write)) {
					Console.SetOut(new StreamWriter(fs));

					RenderContextTest renderContextTest = new RenderContextTest();

					renderContextTest.Run();
					Console.Out.Flush();
				}
				GC.Collect();
			}

			// ShaderProgram
			if (MessageBox.Show("Do you want to execute test ShaderProgram?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
				using (FileStream fs = new FileStream(TestLogName("ShaderProgram"), FileMode.Create, FileAccess.Write)) {
					Console.SetOut(new StreamWriter(fs));

					ShaderProgramest shaderProgramTest = new ShaderProgramest();

					shaderProgramTest.Run();
				}
				GC.Collect();
			}

			// PixelType
			if (MessageBox.Show("Do you want to execute test PixelType?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
				using (FileStream fs = new FileStream(TestLogName("PixelType"), FileMode.Create, FileAccess.Write)) {
					Console.SetOut(new StreamWriter(fs));

					PixelTypeTest pixelTypeTest = new PixelTypeTest();

					pixelTypeTest.Run();
					Console.Out.Flush();
				}
				GC.Collect();
			}

			// Texture
			if (MessageBox.Show("Do you want to execute test Texture?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
				using (FileStream fs = new FileStream(TestLogName("Texture"), FileMode.Create, FileAccess.Write)) {
					Console.SetOut(new StreamWriter(fs));

					TextureTest textureTest = new TextureTest();

					textureTest.Run();
					Console.Out.Flush();
				}
				GC.Collect();
			}

#if false
			using (FileStream fs = new FileStream(TestLogName("ImageCodec"), FileMode.Create, FileAccess.Write)) {
				Console.SetOut(new StreamWriter(fs));
				
				ImageCodecTest imageDisplayTest = new ImageCodecTest();

				imageDisplayTest.Run();
				Console.Out.Flush();
			}
			GC.Collect();
#endif

			// Framebuffer
			if (MessageBox.Show("Do you want to execute test Framebuffer?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
				using (FileStream fs = new FileStream(TestLogName("Framebuffer"), FileMode.Create, FileAccess.Write)) {
					Console.SetOut(new StreamWriter(fs));

					RenderFramebufferTest imageDisplayTest = new RenderFramebufferTest();

					imageDisplayTest.Run();
					Console.Out.Flush();
				}
				GC.Collect();
			}

			// FontObject
			if (MessageBox.Show("Do you want to execute test FontObject?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) {
				using (FileStream fs = new FileStream(TestLogName("FontObject"), FileMode.Create, FileAccess.Write)) {
					Console.SetOut(new StreamWriter(fs));

					FontObjectTest fontObjectTest = new FontObjectTest();

					fontObjectTest.Run();
				}
				GC.Collect();
			}
		}

		static string TestLogName(string testName)
		{
			string outputPath = String.Format(@"{0}Test.txt", testName);

			foreach (char c in Path.GetInvalidFileNameChars())
				outputPath = outputPath.Replace(c, '-');

			return (Path.Combine(@"..\..\..\..\Results", outputPath));
		}
	}
}